package dao;

import java.sql.PreparedStatement;

public class UpdateReservationStatus {

    public static int updateStatus(String appointmentNumber, int a) {
        MyConnection myCon = new MyConnection();
        myCon.getConnection();
        int n = -1;
        try {
            PreparedStatement ps = myCon.connection.prepareStatement(
                    "update appointment set AppointmentCheckStatus=? where AppointmentNumber=?;");
            ps.setInt(1, a);
            ps.setString(2, appointmentNumber);
            n = ps.executeUpdate();
            if (a == 0) {
                ps = myCon.connection.prepareStatement(
                        "update placetime set PlaceStatus=1 where PlaceTimeNumber=(select PlaceTimeNumber from appointment where AppointmentNumber=?);");
                ps.setString(1, appointmentNumber);
            }
            ps.close();

        } catch (Exception e) {
            e.printStackTrace();
        } finally {
            myCon.closeConnection();
        }
        return n;
    }
}
